#!/usr/bin/env python
# encoding: utf-8

def build(bld):
    if not bld.env.BOARD in ['f103-periph', 'CUAV_GPS']:
        return

    bld.ap_stlib(
        name= 'AP_Periph_libs',
        ap_vehicle='AP_Periph',
        ap_libraries= [
        'AP_Buffer',
        'AP_Common',
        'AP_HAL',
        'AP_HAL_Empty',
        'AP_Math',
        'AP_BoardConfig',
        'AP_Param',
        'StorageManager',
        'AP_FlashStorage',
        'AP_GPS',
        'AP_SerialManager',
        'AP_RTC',
        'AP_Compass',
        'AP_Baro',
        'Filter',
        'AP_InternalError',
        ],
        exclude_src=[
            'libraries/AP_HAL_ChibiOS/Storage.cpp'
        ]
    )

    # build external libcanard library
    bld.stlib(source='../../modules/libcanard/canard.c',
              target='libcanard')

    bld.ap_program(
        program_name='AP_Periph',
        use=['AP_Periph_libs', 'libcanard'],
        program_groups=['bin','AP_Periph'],
        includes=[bld.env.SRCROOT + '/modules/libcanard',
                  bld.env.BUILDROOT + '/modules/libcanard/dsdlc_generated']
    )

    bld(
        # build libcanard headers
        rule="python3 ../../modules/libcanard/dsdl_compiler/libcanard_dsdlc --header_only --outdir ${BUILDROOT}/modules/libcanard/dsdlc_generated ../../modules/uavcan/dsdl/uavcan ../../libraries/AP_UAVCAN/dsdl/ardupilot ../../libraries/AP_UAVCAN/dsdl/com",
        group='dynamic_sources',
    )
